package vg.services.graph_view_manager.realization.graph_view.smart_graph_view.realization.actions;

import vg.services.graph_view_manager.interfaces.graph_view.IGraphObserver;
import vg.services.graph_view_manager.interfaces.graph_view.IGraphRenderer;

/**
 * Adds/removes observer to/from a graph view.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public class GraphObserverAction extends DefaultActionAdapter {
    // adding of select observer
    public static final int ADD_SELECT_OBSERVER_ACTION = 1;
    // removing of  select observer
    public static final int REMOVE_SELECT_OBSERVER_ACTION = 2;

    // Main data
    private int action;
    private IGraphObserver observer;

    public GraphObserverAction(int action, IGraphObserver observer) {
        super("add/remove observers");

        this.action = action;
        this.observer = observer;
    }

    @Override
    public void action(final IGraphRenderer graphRenderer) {
        switch (action) {
            case ADD_SELECT_OBSERVER_ACTION:
                graphRenderer.addObserver(observer);
                break;
            case REMOVE_SELECT_OBSERVER_ACTION:
                graphRenderer.removeObserver(observer);
                break;
            default:
                break;
        }
    }
}
